<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        var obj = {  // 普通对象是不可迭代的，但是可以手动书写 Symbol.iterator 属性变成可迭代对象
            a: 1,
            b: 2,
            [Symbol.iterator]() {
                const keys = Object.keys(this);
                let i = 0;
                return {
                    next: () => {
                        const propName = keys[i];
                        const propValue = this[propName];
                        const result = {
                            value: {
                                propName,
                                propValue
                            },
                            done: i >= keys.length
                        }
                        i++;
                        return result;
                    }
                }
            }
        }

        console.log({
            ...obj   // 按照正常的对象的展开方式
        })

        const arr = [...obj];   //展开运算符在这里的作用：调用可迭代对象的迭代器，之后不断加入到数组，和for of 似的
        console.log(arr);

        function test(a, b) {
            console.log(a, b)
        }

        test(...obj);
    </script>
</body>

</html>